//
//  SlidScrollerViewController.m
//  InduceTool
//
//  Created by 魏延龙 on 2020/8/6.
//  Copyright © 2020 魏延龙. All rights reserved.
//

#import "ITSlidScrollerViewController.h"
#import "SlidCommonView.h"
#import "ITSlidReusableView.h"

@interface ITSlidScrollerViewController () <SlidCommonViewDelegate, SlidCollectionViewDataSource>
@property(nonatomic, strong) SlidCommonView *commonView;

@end

@implementation ITSlidScrollerViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    [self setupViews];
}

- (void)viewWillLayoutSubviews {
    self.commonView.frame = self.view.bounds;
}

- (void)setupViews {
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
    flowLayout.itemSize = CGSizeMake(44, 44);
    flowLayout.minimumInteritemSpacing = 28;
    flowLayout.minimumLineSpacing = 24;
    flowLayout.sectionInset = UIEdgeInsetsMake(24, 20, 24, 20);
    flowLayout.footerReferenceSize = CGSizeMake(100, 44);
    
    self.commonView = [[SlidCommonView alloc] initWithSlidViewType:SlidViewTypeCollectionView];
    self.commonView.slidCommonViewDelegate = self;
//    self.commonView.tableViewDataSource = self;
    self.commonView.collectionViewDataSource = self;
    self.commonView.topImageName = @"tt_1";
    [self.commonView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"UITableViewCell"];
    [self.commonView registerClass:[ITSlidReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"footer"];
    [self.commonView setupSlidCollectionViewlayout:flowLayout];
    [self.view addSubview:self.commonView];
}

- (NSInteger)numberOfSectionsInSlidTableView:(UITableView *)tableView {
    return 4;
}
- (NSInteger)slidTableView:(SlidCommonView *)slidCommonView numberOfItemsInSection:(NSInteger)section {
    return 10;
}

- (UITableViewCell *)slidTableView:(SlidCommonView *)slidCommonView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [slidCommonView dequeueReusableCellWithReuseIdentifier:@"UITableViewCell" forIndexPath:indexPath];
    cell.textLabel.text = @"lidCommonView dequeueReusableCellWithReuseIdentifier: forIndexPath:indexPath]";
    return cell;
}

- (CGFloat)slidCommonView:(SlidCommonView *)slidCommonView tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 10;
}

- (UIView *)slidCommonView:(SlidCommonView *)slidCommonView tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    UIView *view = [[UIView alloc] init];
    view.backgroundColor = [UIColor redColor];
    return view;
}

- (NSInteger)slidCollectionView:(SlidCommonView *)slidCommonView numberOfItemsInSection:(NSInteger)section {
    return 200;
}

- (UICollectionViewCell *)slidCollectionView:(SlidCommonView *)slidCommonView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    UICollectionViewCell *cell = [slidCommonView dequeueReusableCellWithReuseIdentifier:@"UITableViewCell" forIndexPath:indexPath];
    cell.backgroundColor = [UIColor redColor];
    return cell;
}

- (UICollectionReusableView *)slidCollectionView:(SlidCommonView *)slidCommonView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {
    if ([kind isEqualToString:UICollectionElementKindSectionFooter]){
        ITSlidReusableView *view = [slidCommonView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:@"footer" forIndexPath:indexPath];
        view.backgroundColor = [UIColor blueColor];
        return view;
    }
    return nil;
}


@end
